package org.voidness.oje2d;

import org.lwjgl.opengl.GL11;

/** A custom color class. */
public class GLColor {
    /** The red component */
    private float red;

    /** The green component */
    private float green;

    /** The blue component */
    private float blue;

    /** The alpha component */
    private float alpha;

    /** A default static color */
    public static final GLColor WHITE = new GLColor(1.0f, 1.0f, 1.0f, 1.0f);

    /** A default static color */
    public static final GLColor BLACK = new GLColor(0.0f, 0.0f, 0.0f, 1.0f);

    /** A default static color */
    public static final GLColor RED = new GLColor(1.0f, 0.0f, 0.0f, 1.0f);

    /** A default static color */
    public static final GLColor GREEN = new GLColor(0.0f, 1.0f, 0.0f, 1.0f);

    /** A default static color */
    public static final GLColor BLUE = new GLColor(0.0f, 0.0f, 1.0f, 1.0f);

    /** A default static color */
    public static final GLColor YELLOW = new GLColor(1.0f, 1.0f, 0.0f, 1.0f);

    /** A default static color */
    public static final GLColor GRAY = new GLColor(0.5f, 0.5f, 0.5f, 1.0f);

    /** A default static color */
    public static final GLColor DARK_GRAY = new GLColor(0.2f, 0.2f, 0.2f, 1.0f);

    /**
     * Default color constructor.
     * 
     * @param mRed The red component of the color
     * @param mGreen The green component of the color
     * @param mBlue The blue component of the color
     * @param mAlpha The alpha component of the color
     */
    public GLColor(float mRed, float mGreen, float mBlue, float mAlpha) {
        red = mRed;
        green = mGreen;
        blue = mBlue;
        alpha = mAlpha;
    }

    /**
     * Generates a random color in full alpha
     * 
     * @return The generated color
     */
    public static GLColor randomColorFullAlpha() {
        float red = (float) Math.random();
        float green = (float) Math.random();
        float blue = (float) Math.random();
        return new GLColor(red, green, blue, 1.0f);
    }

    /**
     * Generates a random color with a minimum alpha
     * 
     * @param mMinimumAlpha The minimum value for the alpha
     * @return The generated color
     */
    public static GLColor randomColor(float mMinimumAlpha) {
        float red = (float) Math.random();
        float green = (float) Math.random();
        float blue = (float) Math.random();
        float alpha = (float) Math.random() + mMinimumAlpha;
        return new GLColor(red, green, blue, alpha);
    }

    /**
     * Get the color's red component.
     * 
     * @return The red value
     */
    public float getRed() {
        return red;
    }

    /**
     * Get the color's green component.
     * 
     * @return The green value
     */
    public float getGreen() {
        return green;
    }

    /**
     * Get the color's blue component.
     * 
     * @return The blue value
     */
    public float getBlue() {
        return blue;
    }

    public float getAlpha() {
        return alpha;
    }

    /**
     * Sets the current color to be this one.
     */
    public void set() {
        GL11.glColor4f(red, green, blue, alpha);
    }

    /**
     * (Re)defines the color's alpha value.
     * 
     * @param mAlpha The value to set (0.0f - 1.0f)
     */
    public void setAlpha(float mAlpha) {
        alpha = mAlpha;
    }

    /**
     * Resets the current color to white.
     */
    public void reset() {
        GL11.glColor4f(1.0f, 1.0f, 1.0f, 1.0f);
    }

    /**
     * Gets a shade of gray
     * 
     * @param shade The 0.0-1.0 value that you want
     * @return The gray GLColor
     */
    public static GLColor getGray(float shade) {
        return new GLColor(shade, shade, shade, 1.0f);
    }
}